package com.yl.pattern.behavioralmodel.state.after;

/**
 * @Author 小羊
 * @Date 1/11/2024下午 2:47
 * @ClassName Context
 * @Description 环境角色类
 */
public class Context {
    /**
     * 定义对应状态的常量
     */
    public static final OpeningState OPENING_STATE = new OpeningState();
    public static final ClosingState CLOSING_STATE = new ClosingState();
    public static final RunningState RUNNING_STATE = new RunningState();
    public static final StoppingState STOPPING_STATE = new StoppingState();
    /**
     * 定义一个当前电梯状态变量
     */
    private LiftState state;

    public LiftState getState() {
        return state;
    }

    public void setState(LiftState state) {
        this.state = state;
        this.state.setContext(this);
    }
    public void open(){
        this.state.open();
    }
    public void close(){
        this.state.close();
    }
    public void run(){
        this.state.run();
    }
    public void stop(){
        this.state.stop();
    }
}
